#include<stdio.h>

int maxArea(int* arr, int heightSize) { // initial verse
    int max = 0;
    for (int i = 0; i < heightSize; i++)
    {
        for (int j = i + 1; j < heightSize; j++)
        {
            int small = arr[j];
            if (arr[j] > arr[i])
            {
                small = arr[i];
            }
            int mix = small * (j - i);
            if (mix > max)
            {
                max = mix;
            }
        }
    }
    return max;
}
int maxArea(int* arr, int heightSize) { //optimal verse
    int arrdown = heightSize - 1;
    int arrup = 0;
    int max = 0;
    while (arrup < arrdown)
    {
        int mini = fmin(arr[arrdown], arr[arrup]);
        int area = mini * (arrdown - arrup);
        if (area > max)
        {
            max = area;
        }
        if (arr[arrdown] < arr[arrup])
        {
            arrdown -= 1;
        }
        else
        {
            arrup++;
        }
    }
    return max;
}
int main()
{
    int arr[] = { 1,8,6,2,5,4,8,3,7 };
    int sz = sizeof(arr) / sizeof(arr[0]);
    int max = maxArea(arr, sz);
    return 0;
}